namespace C1.Win.C1FlexGrid
{
    using System;
    using System.Collections;

    public class Row : RowCol
    {
        internal ArrayList _cellData;
        internal ArrayList _cellInfo;
        internal int _index;
        internal short _nodeLevel;

        internal Row(RowCollection coll)
        {
            base._coll = coll;
        }

        public override void Clear(ClearFlags clear)
        {
            base.Clear(clear);
            if (((clear & ClearFlags.Content) != 0) && (base._coll != null))
            {
                GridModel model = base._coll._grid;
                int row = this.Index;
                for (int i = 0; i < model._cols.Count; i++)
                {
                    model.ClearCell(row, i, ClearFlags.Content);
                }
            }
        }

        public int Bottom
        {
            get
            {
                return base.End;
            }
        }

        public string Caption
        {
            get
            {
                if (base._coll != null)
                {
                    GridModel model = base._coll._grid;
                    if ((model != null) && (model._rows._fixed > 0))
                    {
                        return model.GetDataDisplay(this.SafeIndex, 0);
                    }
                }
                return string.Empty;
            }
            set
            {
                if (base._coll != null)
                {
                    GridModel model = base._coll._grid;
                    if ((model != null) && (model._rows._fixed > 0))
                    {
                        model.SetData(this.SafeIndex, 0, value, false);
                    }
                }
            }
        }

        public int DataIndex
        {
            get
            {
                if (base._coll == null)
                {
                    return -1;
                }
                base._coll.Update();
                return base._dataIndex;
            }
        }

        public int Height
        {
            get
            {
                return base.Size;
            }
            set
            {
                base.Size = value;
            }
        }

        public int HeightDisplay
        {
            get
            {
                return base.SizeDisplay;
            }
            set
            {
                base.SizeDisplay = value;
            }
        }

        public override int Index
        {
            get
            {
                if (base._coll == null)
                {
                    return -1;
                }
                base._coll.Update();
                return this._index;
            }
        }

        public bool IsNode
        {
            get
            {
                return (((short) (base._flags & RowColFlags.IsNode)) != 0);
            }
            set
            {
                if ((this.IsNode != value) && (base._coll != null))
                {
                    GridModel model = base._coll._grid;
                    model.AssertNotBound();
                    if (!value)
                    {
                        this.Node.Collapsed = false;
                    }
                    model._tree.SetIsNode(this, value);
                }
            }
        }

        public C1.Win.C1FlexGrid.Node Node
        {
            get
            {
                if (base._coll != null)
                {
                    return base._coll._grid._tree.GetNode(this);
                }
                return null;
            }
        }

        public virtual int SafeIndex
        {
            get
            {
                int num = this.Index;
                if (num < 0)
                {
                    throw new Exception("Row does not belong to grid.");
                }
                return num;
            }
        }

        public override bool Selected
        {
            get
            {
                return (((short) (base._flags & RowColFlags.Selected)) != 0);
            }
            set
            {
                if (this.Selected != value)
                {
                    base.SetFlags(RowColFlags.Selected, value);
                    if (base._coll != null)
                    {
                        base._coll.NotifyViews(GridChangedTypeEnum.RowSelected, this.Index, -1);
                    }
                }
            }
        }

        public int Top
        {
            get
            {
                return base.Beg;
            }
        }
    }
}

